<cfparam name="cid" default="0">
<cfparam name="view_month" default="0">
<cfparam name="view_year" default="#dateformat(now(), 'yyyy')#">
<cfparam name="start" default="1">
<cfparam name="disp" default="25">
<cfparam name="page" default="1">

<cfcookie name="cid" value="#cid#" expires="NOW">
<cfcookie name="view_month" value="#view_month#" expires="NOW">
<cfcookie name="view_year" value="#view_year#" expires="NOW">
<cfcookie name="start" value="#start#" expires="NOW">
<cfcookie name="disp" value="#disp#" expires="NOW">         

<cfset cid = cookie.cid>
<cfset view_month = cookie.view_month>
<cfset view_year = cookie.view_year>
<cfset start = cookie.start>

<cfinvoke component="cfcs.blog" method="getpostcount" returnvariable="totalrecords" 
cid="#cid#" 
view_month="#view_month#" 
view_year="#view_year#" />

<cfset sqlstart = start - 1>
<cfset sqlend = disp>

<cfinvoke component="cfcs.blog" method="getallposts" returnvariable="qposts" 
startrow="#sqlstart#" 
endrow="#sqlend#" 
cid="#cid#" 
view_month="#view_month#" 
view_year="#view_year#" />

<cfinvoke component="cfcs.blog" method="getcategories" returnvariable="qcats" />

<!---get first post to figure out year--->
<cfquery name="qfirstpost" dbtype="query">
SELECT * FROM qposts
<cfif cid GT 0>WHERE cid = <cfqueryparam value="#cid#" cfsqltype="cf_sql_integer"></cfif>
ORDER BY b_postedon ASC
</cfquery>

<cfif qfirstpost.recordcount IS 0>
	<cfset firstblogyear = dateformat(now(), "yyyy")>
<cfelse>
	<cfset firstblogyear = dateformat(qfirstpost.b_postedon, "yyyy")>
</cfif>

<table width="100%" border="0" cellspacing="0" cellpadding="6">
<cfoutput>
  <form name="viewform" method="post" action="index.cfm?c=blog">
  <tr>
    <td><select name="cid" id="cid">
        <option value="0" <cfif cid IS 0>selected="selected"</cfif>>All Categories</option>
        <cfloop query = "qcats">
        <option value = "#id#" <cfif cid IS id>selected="selected"</cfif>>#cname#</option>
        </cfloop>
      </select>
      <input type="submit" name="abutton" id="abutton" value="#request.lang.blog.posts.button1#" />    </td>
    <td align="right">
    <select name="view_month" id="view_month">
    	<option value="0" <cfif view_month IS 0>selected="selected"</cfif>>All Months</option>
    	<cfloop from="1" to="12" index="thismonth">
        	<cfset thedate = '#thismonth#/1/#dateformat(now(), "yyyy")#'>
        	<option id="#thismonth#" <cfif view_month IS thismonth>selected="selected"</cfif>>#MonthAsString(Month(thedate))#</option>
        </cfloop> 
    </select>   
	<cfset thisyear = #dateformat(now(), "yyyy")#>
	<select name="view_year" id="view_year">
    	<cfloop from="#thisyear#" to="#firstblogyear#" step="-1" index="yr">
        <option id="#yr#" <cfif view_year IS yr>selected="selected"</cfif>>#yr#</option>
        </cfloop>
    </select>    
    <input type="submit" name="abutton" id="abutton" value="#request.lang.blog.posts.button2#" />    </td>
  </tr>
  <tr>
    <td colspan="2">
		 <cfif qposts.recordcount GT 0>
		<!---pagination--->
		<cfinvoke component="cfcs.common.paginate" method="show" start="#start#" disp="#disp#" totalrecords="#totalrecords#" page="#page#" url="index.cfm?c=blog&a=default" />
        </cfif>    </td>
    </tr>
 </form>
</cfoutput>
</table>
<cfoutput>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
  <tr>
    <td id="columnheaders">#request.lang.blog.posts.col1#</td>
    <td width="25%" id="columnheaders">#request.lang.blog.posts.col2#</td>
    <td width="15%" id="columnheaders"></td>
  </tr>
  <cfloop query = "qposts">
  <tr class="menu_row" onmousedown="this.className = 'menu_row_over';" onmouseover = "this.className = 'menu_row_over2';" onmouseup="this.className = 'menu_row_over';" onmouseout = "this.className = 'menu_row';">
    <td class="menu_cell" onclick="window.location.href = 'index.cfm?c=blog&a=edit&b_id=#b_id#&formaction=EDIT';"><div style="font-weight: bold;">#b_title# <cfif len(trim(b_author)) GT 0>(By #b_author#)</cfif></div></td>
    <td class="menu_cell" onclick="window.location.href = 'index.cfm?c=blog&a=edit&b_id=#b_id#&formaction=EDIT';">#dateformat(b_postedon, "mmm dd, yyyy")# at #timeformat(b_postedon, "hh:mm tt")#</td>
    <td class="menu_cell"><div align="center"><a href="index.cfm?c=blog&a=edit&b_id=#b_id#&formaction=EDIT"><img src="images/edit.png" border="0" title="#request.lang.defaults.tooltip_edit#" alt="#request.lang.defaults.tooltip_edit#" /></a>&nbsp; 
        &nbsp;<a href="index.cfm?c=blog&a=delete&b_id=#b_id#"><img src="images/delete.png" border="0" title="#request.lang.defaults.tooltip_del#" alt="#request.lang.defaults.tooltip_del#" /></a>&nbsp;&nbsp; &nbsp;<a href = "index.cfm?c=metadata&a=forfile&for_file=#b_file#&wasdoing=blog"><img src="images/meta.png" border="0" title="#request.lang.defaults.tooltip_meta#" alt="#request.lang.defaults.tooltip_meta#" /></a></div></td>
  </tr>
  </cfloop>
   <cfif qposts.recordcount IS 0>
   <tr class="menu_row">
   	<td colspan="3"><span style="font-style: italic; font-weight: bold;">#request.lang.blog.posts.norecordsmsg#</span></td>
   </tr>
   </cfif>
</table>
</cfoutput>